<template>
    <div class="list">
        <div class="table" v-if="active===1">
            <div class="card">
                <el-form :model="params" style="width: 100%;">
                    <el-container>
                        <!--内容-->
                        <el-form-item>
                            <el-input v-model="params.content" style="width: 200px;"></el-input>
                        </el-form-item>
                        <!--字段类型-->
                        <el-form-item style="margin-left: 10px">
                            <el-select v-model="params.type" :value="params.type" style="width: 200px;">
                                <el-option
                                        v-for="type in typeList"
                                        :label="type.value"
                                        :value="type.key"
                                        :key="type.key"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                        <!--案件类型-->
                        <el-form-item style="margin-left: 10px">
                            <el-select v-model="params.caseType" :value="params.caseType" style="width: 150px;">
                                <el-option label="案件类型" value=""></el-option>
                                <el-option
                                        v-for="caseType in caseTypeList"
                                        :label="caseType.caseTypeName"
                                        :value="caseType.id"
                                        :key="caseType.id"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item style="margin-left: 10px">
                            <el-button type="primary" @click="handleSearch">检索</el-button>
                        </el-form-item>
                    </el-container>
                </el-form>

                <el-table :border="true" :data="pageResult.records">
                    <el-table-column prop="id" v-if="false"></el-table-column>
                    <el-table-column label="案号" prop="caseNo"></el-table-column>
                    <el-table-column label="案由" prop="caseCause"></el-table-column>
                    <el-table-column label="收案日期" prop="collectionTime"></el-table-column>
                    <el-table-column label="委托人/当事人" prop="caseWtr"></el-table-column>
                    <el-table-column label="对方当事人" prop="caseOppositeParties" width="100px"></el-table-column>
                    <el-table-column label="承办律师" prop="caseAttorney" width="200px"></el-table-column>
                    <el-table-column label="代理费" prop="caseAgencyfee" width="70px"></el-table-column>
                    <el-table-column label="收案审批人" prop="systemApprovalName" width="100px"></el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="text" @click="handleShowDetails(scope.row.id)">查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <el-footer class="case-list-footer">
                    <el-pagination
                            style="margin: 10px auto"
                            background
                            layout="prev, pager, next"
                            :total="pageResult.total"
                            :page-size="pageResult.size"
                            class="pagination"
                            @current-change="handleIndexChange"
                    >
                    </el-pagination>
                </el-footer>
            </div>
        </div>

        <div style="width: 100%;" v-if="active==2">
            <yongyin-details :law="law" :sealList="sealList" @back="back"></yongyin-details>
        </div>
    </div>
</template>

<script>
    //引入组件
    const YongyinDetails = () => import('../Yongyin/YongyinDetails.vue')
    //引入案件类型服务类
    import CaseTypeService from '../../../model/gs/CaseTypeService.js'
    import CaseLawService from '../../../model/gs/CaseLawService.js'
    import {CaseSealApplyforService} from "../../../model/gs/CaseSealApplyforService";

    const caseTypeService = CaseTypeService.getInstance()
    const caseLawService = CaseLawService.getInstance()
    const caseSealApplyforService = CaseSealApplyforService.getInstance()

    export default {
        data() {
            return {
                //控制跳转的变量
                active:1,
                //表格选中的一行的对象
                law:{},
                sealList:[],
                pageResult:{},
                params:{
                    type:'case_wtr/case_suspect',
                    caseType:'',
                    recycle:'Y'
                },
                caseTypeList:[],
                typeList:[
                    {
                        key:'case_wtr/case_suspect',
                        value:'委托人/嫌疑人搜索'
                    },
                    {
                        key:'case_opposite_parties',
                        value:'对方当事人搜索'
                    },
                    {
                        key:'case_no',
                        value:'案号搜索'
                    },
                    {
                        key:'case_cause',
                        value:'案由搜索'
                    },
                    {
                        key:'case_attorney',
                        value:'承办律师搜索'
                    },
                    {
                        key:'case_accept',
                        value:'受理机关搜索'
                    }
                ],
            }
        },
        methods:{
            //返回上一个路由的方法
            goBack(){
                history.back()
            },
            back(){
                this.active = 1
            },
            //检索按钮点击事件
            handleSearch(){
                //重置当前页为1
                this.params.page = 1
                this.getCaseLaws()
            },
            //获取案件的方法
            getCaseLaws(){
                caseLawService.getByPage(this.params).then(response => {
                    if(response.data.code === 0){
                        this.pageResult = response.data.data
                    }
                })
            },
            //获取案件类型的方法
            getCaseTypeList(){
                caseTypeService.parentList().then(response => {
                    if(response.data.code === 0){
                        this.caseTypeList = response.data.data
                    }
                })
            },
            //当前页放生变化的事件
            handleIndexChange(index){
                this.params.page = index
                this.getCaseLaws()
            },
            handleShowDetails(id){
                //通过案件id查询文书和案件信息
                this.$axios.all([caseLawService.getById(id),
                    caseSealApplyforService.getByCaseLaw(id)])
                    .then(this.$axios.spread((lawResponse,sealResponse) => {
                        this.law=lawResponse.data.data
                        this.sealList=sealResponse.data.data
                        this.active++
                    }))
            }
        },
        created(){
            this.getCaseTypeList()
            this.getCaseLaws()
        },
        components:{
            YongyinDetails
        }
    }
</script>

<style scoped>
    .list{
        width: 100%;
    }
    .card{
        width: 100%;
    }
    .case-list-footer{
        width: 100%;
        height: 10%;
        position: relative;
    }
    .case-list-footer .pagination{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translateY(-50%) translateX(-50%);
    }
    .table{
        width: 100%;
    }
</style>